package com.auto.learning.fragment;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.auto.learning.MainActivity;
import com.auto.learning.R;
import com.auto.learning.activity.SearchActivity;
import com.auto.learning.adapter.HomePageListViewAdapter;
import com.auto.learning.bean.BannerItem;
import com.auto.learning.bean.BookBean;
import com.auto.learning.bean.ResponeResult;
import com.auto.learning.event.BuySuccessEvent;
import com.auto.learning.event.CollectEvent;
import com.auto.learning.event.EventBus;
import com.auto.learning.event.Handle;
import com.auto.learning.image.viewpager.NetworkImageHolderView;
import com.auto.learning.net.Cache;
import com.auto.learning.net.HttpRequestHelper;
import com.auto.learning.thread.pool.Pool;
import com.auto.learning.tools.CommonMethod;
import com.auto.learning.view.PullToRefreshListView;
import com.auto.learning.view.PullToRefreshListView.OnRefreshListener;
import com.auto.learning.view.SharedPreferencesUtils;
import com.baidu.mobstat.StatService;
import com.bigkoo.convenientbanner.CBViewHolderCreator;
import com.bigkoo.convenientbanner.ConvenientBanner;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.squareup.otto.Subscribe;
import com.squareup.otto.ThreadEnforcer;

/**
 * 首页第三版本
 * 
 * @author wangjianjun
 */
public class HomePageFragment extends Fragment {
	private static final int GETDATA_SUCCESS = 1;
	private static final int GETDATA_FAIL = 2;
	private static final int NEW_GETDATA_SUCCESS = 3;
	private static final int TOP_GETDATA_SUCCESS = 4;
	private static final int CONTINUE_TIP = 5;
	private static final int REFRESH_New_TopBook = 6;
	private static final int TOP_MONTH_GETDATA_SUCCESS = 7;
	private static final int WEEK = 8;
	private static final int MONTH = 9;
	private static final int BUY_SUCCESS = 14;
	private ConvenientBanner<BannerItem> convenientBanner;
	private ArrayList<BannerItem> list = new ArrayList<BannerItem>();
	private ArrayList<BookBean> allBookList = new ArrayList<BookBean>(); // 所有
	private ArrayList<BookBean> bookList = new ArrayList<BookBean>(); // 猜你喜欢
	private ArrayList<BookBean> newList = new ArrayList<BookBean>(); // 每周新书
	private ArrayList<BookBean> topList = new ArrayList<BookBean>(); // 周（月）排行版
	private ArrayList<BookBean> topMonthList = new ArrayList<BookBean>(); // 月排行版
	private PullToRefreshListView listView;
	private HomePageListViewAdapter adapter;
	View view = null;
	private LinearLayout linear_search;
	private RelativeLayout rel_tip;
	TextView tv_tip, load_more;;
	ImageView image_close;

	private View lvProductFooter;
	private TextView lvProductFooterMore;
	private ProgressBar lvProductFooterProgress;
	private TextView lvBtn_more;
	private LinearLayout lvLinear_more;

	private int pageIndex = 0;
	private int currentContinueBookId = 0;
	private int currentListShowIsWeekTop = 0; // 当前列表要显示的是周榜还是月榜，0为周榜，1为月榜

	private Handle handle = new Handle(getActivity()) {
		public void handleMessage(Message msg) {
			super.handleMessage(msg);
			switch (msg.what) {
			case BUY_SUCCESS:
				if (list != null) {
					for (int i = 0; i < list.size(); i++) {
						if (list.get(i).getType() == 1) {
							if (list.get(i).getBookModel() != null && list.get(i).getBookModel().getBookId() == msg.arg1) {
								list.get(i).getBookModel().setNeedBuy(1);
							}
						}
					}
					convenientBanner.setPages(
						new CBViewHolderCreator<NetworkImageHolderView>() {
							@Override
							public NetworkImageHolderView createHolder() {
								return new NetworkImageHolderView();
							}
					}, list);
				}
				break;
			case GETDATA_SUCCESS:
				ResponeResult result = (ResponeResult) msg.obj;
				ArrayList<BookBean> t_bookList = new Gson().fromJson(result.getData(), new TypeToken<ArrayList<BookBean>>() {}.getType());
				String buttom = "";
				String tag = "";
				if (t_bookList != null) {
					boolean isLike = false;
					if (pageIndex == 0) {
						bookList.clear();
						bookList.addAll(t_bookList);
						isLike = true;
					} else {
						bookList.addAll(t_bookList);
					}
					if (t_bookList.size() > 0) {
						buttom = "";
						pageIndex++;
						tag = "0";
						lvBtn_more.setVisibility(View.VISIBLE);
						lvProductFooterMore.setText(buttom);
						lvProductFooterProgress.setVisibility(View.GONE);
					} else {
						tag = "1";
						buttom = getResources().getString(R.string.text_hompage_data);
						lvLinear_more.setVisibility(View.VISIBLE);
						lvProductFooterMore.setText(buttom);
						lvProductFooterProgress.setVisibility(View.GONE);
						lvBtn_more.setVisibility(View.GONE);
					}

					load_more.setTag(tag);
					load_more.setText(buttom);
					load_more.setVisibility(View.VISIBLE);

					organizeData();
					notifyUI();
					handle.sendEmptyMessage(11);
					linear_search.setVisibility(View.VISIBLE);
					Log.d("l_positiom", listView.getScrollY() + "");
					Cache.cacheBook2Local(t_bookList, isLike);
					((MainActivity) getActivity()).showRefreshTips();
				}
				break;
			case NEW_GETDATA_SUCCESS:
				ResponeResult new_result = (ResponeResult) msg.obj;
				ArrayList<BookBean> new_bookList = new Gson().fromJson(new_result.getData(), new TypeToken<ArrayList<BookBean>>() {}.getType());
				if (new_bookList != null) {
					newList.clear();
					newList.addAll(new_bookList);
					Cache.cacheNewOrTopBookList2Local(new_bookList, 2);
					organizeData();
					notifyUI();
				}
				break;
			case TOP_GETDATA_SUCCESS:
				ResponeResult top_result = (ResponeResult) msg.obj;
				ArrayList<BookBean> top_bookList = new Gson().fromJson(top_result.getData(), new TypeToken<ArrayList<BookBean>>() {}.getType());
				if (top_bookList != null) {
					topList.clear();
					topList.addAll(top_bookList);
					Cache.cacheNewOrTopBookList2Local(top_bookList, 3);
					organizeData();
					notifyUI();
				}
				break;
			case TOP_MONTH_GETDATA_SUCCESS:
				ResponeResult top_month_result = (ResponeResult) msg.obj;
				ArrayList<BookBean> top_month_bookList = new Gson().fromJson(
						top_month_result.getData(),
						new TypeToken<ArrayList<BookBean>>() {
						}.getType());
				if (top_month_bookList != null) {
					topMonthList.clear();
					topMonthList.addAll(top_month_bookList);
					organizeData();
					notifyUI();
				}
				break;
			case CONTINUE_TIP:
				BookBean m_bookBean = (BookBean) msg.obj;
				if (m_bookBean != null) {
					tv_tip.setText("点击继续播放：" + m_bookBean.getBookName() + "");
				}
				break;
			case WEEK:
				currentListShowIsWeekTop = 0;
				organizeData();
				notifyUI();
				break;
			case MONTH:
				currentListShowIsWeekTop = 1;
				if (topMonthList == null || (topMonthList != null && topMonthList.size() == 0)) {
					getTopMonthBookList();
				} else {
					organizeData();
					notifyUI();
				}
				break;
			case GETDATA_FAIL:
				CommonMethod.makeNotice(getActivity(), (String) msg.obj);
				handle.sendEmptyMessage(11);
				break;
			case REFRESH_New_TopBook:
				if (newList != null) changePlayStatus(newList, msg.arg1);
				if (topList != null) changePlayStatus(topList, msg.arg1);
				if (bookList != null) changePlayStatus(bookList, msg.arg1);
				if (topMonthList != null) changePlayStatus(topMonthList, msg.arg1);
				if (adapter != null) {
					adapter.notifyDataSetChanged();
				}
				break;
			case 11:
				if (convenientBanner != null) {
					convenientBanner.startTurning(4000);
				}
				if (listView != null) {
					listView.onRefreshComplete();
					listView.setTag(0);
				}
				break;
			case 10:
				ArrayList<BannerItem> tempList = (ArrayList<BannerItem>) msg.obj;
				if (list != null) {
					list.clear();
					list.addAll(tempList);

					convenientBanner.setPages(
							new CBViewHolderCreator<NetworkImageHolderView>() {
								@Override
								public NetworkImageHolderView createHolder() {
									return new NetworkImageHolderView();
								}
							}, list);
				}
				break;

			}

		};
	};
	
	private void changePlayStatus(ArrayList<BookBean> list, int bookId){
		for (int i = 0; i < list.size(); i++) {
			if (list.get(i).getBookId() == bookId) {
				list.get(i).setIsRead(2);
				break;
			}
		}
	}

	private void organizeData() {
		allBookList.clear();
		if (newList != null && newList.size() > 0) {
			if (newList.get(0).getBookId() > 0) {
				BookBean newBookBean = new BookBean();
				newBookBean.setBookId(0);
				newBookBean.setBookName("每周新书");
				newList.add(0, newBookBean);
				
			}
		
			allBookList.addAll(newList);
		}
		if (currentListShowIsWeekTop == 0) {
			if (topList != null && topList.size() > 0) {
				if (topList.get(0).getBookId() > 0) {
					BookBean topBookBean = new BookBean();
					topBookBean.setBookId(-1);
					topBookBean.setBookName("周榜top10");
					topList.add(0, topBookBean);
				}
				allBookList.addAll(topList);
			}
		} else if (currentListShowIsWeekTop == 1) {
			if (topMonthList != null && topMonthList.size() > 0) {
				if (topMonthList.get(0).getBookId() > 0) {
					BookBean topBookBean = new BookBean();
					topBookBean.setBookId(-2);
					topBookBean.setBookName("月榜top10");
					topMonthList.add(0, topBookBean);
				}
				allBookList.addAll(topMonthList);
			}
		}
		if (bookList != null && bookList.size() > 0) {
			if (bookList.get(0).getBookId() > 0) {
				BookBean likeBookBean = new BookBean();
				likeBookBean.setBookId(0);
				likeBookBean.setBookName("猜你喜欢");
				bookList.add(0, likeBookBean);
			}
			allBookList.addAll(bookList);
		}
	}

	@SuppressLint("InflateParams")
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fg_first2, null);
		registerEvent();
		initView(view);
		return view;
	}

	public void initView(View view) {
		organizeData();
		lvProductFooter = getActivity().getLayoutInflater().inflate(R.layout.listview_footer, null);
		lvProductFooterMore = (TextView) lvProductFooter.findViewById(R.id.listview_foot_more);
		lvProductFooterProgress = (ProgressBar) lvProductFooter.findViewById(R.id.listview_foot_progress);
		lvBtn_more = (TextView) lvProductFooter.findViewById(R.id.btn_more);
		lvLinear_more = (LinearLayout) lvProductFooter.findViewById(R.id.linear_more);

		listView = (PullToRefreshListView) view.findViewById(R.id.main_listview);
		adapter = new HomePageListViewAdapter(getActivity(), allBookList, 5,handle);
		listView.setAdapter(adapter);

		load_more = (TextView) view.findViewById(R.id.load_more);
		load_more.setTag("0");
		load_more.setVisibility(View.GONE);
		load_more.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (v.getTag().toString().equals("0")) {
					load_more.setTag("1");
					getBookListByPageIndex();
				}
			}
		});

		View bannerView = LayoutInflater.from(getActivity()).inflate(R.layout.fg_first2_top, null);
		rel_tip = (RelativeLayout) bannerView.findViewById(R.id.rel_tip);
		tv_tip = (TextView) bannerView.findViewById(R.id.tv_tip);
		image_close = (ImageView) bannerView.findViewById(R.id.image_close);
		linear_search = (LinearLayout) bannerView.findViewById(R.id.linear_search);
		linear_search.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				StatService.onEvent(getActivity(),"LogEventTypeHomePageSearchBar", "首页搜索栏点击");
				getActivity().startActivity(new Intent(getActivity(), SearchActivity.class));
				getActivity().overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out);
			}
		});
		int[] pageS = { R.drawable.page_unselect, R.drawable.page_select };
		convenientBanner = (ConvenientBanner<BannerItem>) bannerView.findViewById(R.id.convenientbanner);
		updateBannerHight();
		convenientBanner.setPages(new CBViewHolderCreator<NetworkImageHolderView>() {
			@Override
			public NetworkImageHolderView createHolder() {
				return new NetworkImageHolderView();
			}
		}, list);
		convenientBanner.setPointViewVisible(true);
		convenientBanner.setPageIndicator(pageS);
		((MainActivity)getActivity()).addIgnoredView(convenientBanner);
		listView.addHeaderView(bannerView);
		listView.addFooterView(lvProductFooter);
		// lvProductFooter.setVisibility(View.GONE);

		linear_search.setVisibility(View.VISIBLE);


		listView.setOnRefreshListener(new OnRefreshListener() {
			@Override
			public void onRefresh() {
				pageIndex = 0;
				getBookListByPageIndex();
				getNewBookList();
				getTopWeekBookList();
				getBeanerList();
			}
		});
		listView.setTag("1");
		listView.setOnScrollListener(new OnScrollListener() {

			@Override
			public void onScrollStateChanged(AbsListView view, int scrollState) {
				listView.onScrollStateChanged(view, scrollState);
				boolean scrollEnd = false;
				try {
					if (view.getPositionForView(lvProductFooter) == view.getLastVisiblePosition()
							&& !lvProductFooterMore.getText().toString().equals(getResources().getString(R.string.text_hompage_data))) {
						scrollEnd = true;
					}
				} catch (Exception e) {
					scrollEnd = false;
				}
				int lvDataState = Integer.parseInt((listView.getTag().toString()));
				if (scrollEnd && lvDataState == 0) {
					listView.setTag(1);
					lvProductFooterMore.setText("加载中");
					lvProductFooterProgress.setVisibility(View.VISIBLE);
					lvLinear_more.setVisibility(View.VISIBLE);
					lvBtn_more.setVisibility(View.GONE);
					int page = listView.getCount() - 2; // 减去ListView的头和尾的
					Log.d("l_position", "onScrollStateChanged");
					getBookListByPageIndex();
				}
			}

			@Override
			public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
				listView.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount);
			}
		});
		getBeanerList();
		// getBookListByPageIndex();
		boolean CONTINUE_PLAY_BEFORE = (boolean) SharedPreferencesUtils.getParam(getActivity(), HttpRequestHelper.CONTINUE_PLAY_BEFORE, true);
		int c_booKId = (int) SharedPreferencesUtils.getParam(getActivity(), HttpRequestHelper.CONTINUE_PLAY_BOOKID, 0);
		if (CONTINUE_PLAY_BEFORE && c_booKId > 0) {
			getLoacl(c_booKId);
		} else {
			rel_tip.setVisibility(View.GONE);
		}
		image_close.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				rel_tip.setVisibility(View.GONE);
			}
		});
		rel_tip.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				((MainActivity) getActivity()).playContunie();
			}
		});
		listView.clickRefresh();
	}

	public void hideTip() {
		try {
			if (rel_tip != null) {
				rel_tip.setVisibility(View.GONE);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void updateBannerHight() {
		LinearLayout.LayoutParams para = (LayoutParams) convenientBanner.getLayoutParams();
		WindowManager wm = (WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE);
		int width = wm.getDefaultDisplay().getWidth();
		para.height = width/ 5 * 2;
		convenientBanner.setLayoutParams(para);
	}

	@Subscribe
	public void onEventCollect(CollectEvent event) {
		if (bookList != null && bookList.size() > 0) {
			for (int i = 0; i < bookList.size(); i++) {
				if (event.getBookId() == bookList.get(i).getBookId()) {
					bookList.get(i).setIsFavor(event.isCollect() ? 2 : 1);
				}
			}
			if (adapter != null) {
				adapter.notifyDataSetChanged();
			}
		}
	}

	public void notifyUI() {
		if (adapter != null) {
			adapter.notifyDataSetChanged();
		}
		if (listView != null) {
			listView.onRefreshComplete();
		}
	}

	public void startTurning() {
		try {
			if (convenientBanner != null) {
				convenientBanner.startTurning(4000);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

	public void stopTurning() {
		try {
			if (convenientBanner != null) {
				convenientBanner.stopTurning();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public void onResume() {
		super.onResume();
		startTurning();
	}

	@Override
	public void onPause() {
		super.onPause();
		stopTurning();
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
		unRegisterEvent();
	}

	@Subscribe
	public void onEventHttpRequest(ResponeResult result) {
		switch (result.getTag()) {
		case "home_page_banner_list":
			ArrayList<BannerItem> t_list = new Gson().fromJson(result.getData(), new TypeToken<ArrayList<BannerItem>>() {}.getType());
			handle.obtainMessage(10, t_list).sendToTarget();
			Cache.cacheBanner2Local(t_list);
			break;
		}
	}
	
	@Subscribe
	public void onEventBuySuccess(BuySuccessEvent buySuccessEvent){
		handle.obtainMessage(BUY_SUCCESS, buySuccessEvent.getBookId(), 0).sendToTarget();
	}

	public void registerEvent() {
		EventBus.getEventBus("home_page_banner_list", ThreadEnforcer.MAIN).register(this);
		EventBus.getEventBus("m_buy_success",ThreadEnforcer.MAIN).register(this);
		// EventBus.getEventBus(HttpRequestHelper.COLLECT_EVENT,ThreadEnforcer.MAIN).register(this);
	}

	public void unRegisterEvent() {
		EventBus.getEventBus("home_page_banner_list", ThreadEnforcer.MAIN).unregister(this);
		EventBus.getEventBus("m_buy_success",ThreadEnforcer.MAIN).unregister(this);
		// EventBus.getEventBus(HttpRequestHelper.COLLECT_EVENT,ThreadEnforcer.MAIN).unregister(this);
	}

	public void getBeanerList() {
		HttpRequestHelper.getBannerList(getActivity(), handle);
	}

	/**
	 * 获取猜你喜欢列表
	 * 
	 * @param _context
	 * @param _handle
	 */
	public void getBookList() {
		int c_booKId = (int) SharedPreferencesUtils.getParam(getActivity(),HttpRequestHelper.CONTINUE_PLAY_BOOKID, 0);
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair(HttpRequestHelper.USERID, String.valueOf(SharedPreferencesUtils.getParam(getActivity(),HttpRequestHelper.USERID, 0))));
		params.add(new BasicNameValuePair(HttpRequestHelper.BOOKID, String.valueOf(c_booKId)));
		// HttpHelper.executeHttpRequest(getActivity(), "home_page_guess_you_like_list", HttpRequestHelper.GUESS_YOU_LIKE, params, handle);
		HttpRequestHelper.getGuessYouLike(getActivity(),HttpRequestHelper.USER_LIKE, params, handle, GETDATA_SUCCESS, GETDATA_FAIL);
	};

	/**
	 * 获取猜你喜欢列表
	 * 
	 * @param _context
	 * @param _handle
	 */
	public void getBookListByPageIndex() {
		int c_booKId = (int) SharedPreferencesUtils.getParam(getActivity(),HttpRequestHelper.CONTINUE_PLAY_BOOKID, 0);
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair(HttpRequestHelper.USERID, String.valueOf(SharedPreferencesUtils.getParam(getActivity(),HttpRequestHelper.USERID, 0))));
		if (pageIndex == 0) {
			params.add(new BasicNameValuePair(HttpRequestHelper.BOOKID, String.valueOf(c_booKId)));
			currentContinueBookId = c_booKId;
		} else {
			params.add(new BasicNameValuePair(HttpRequestHelper.BOOKID, String.valueOf(currentContinueBookId)));
		}
		params.add(new BasicNameValuePair(HttpRequestHelper.PAGE_INDEX, String.valueOf(pageIndex)));
		// HttpHelper.executeHttpRequest(getActivity(),"home_page_guess_you_like_list", HttpRequestHelper.GUESS_YOU_LIKE,params, handle);
		HttpRequestHelper.getGuessYouLike(getActivity(),HttpRequestHelper.GUESS_YOU_LIKE, params, handle,GETDATA_SUCCESS, GETDATA_FAIL);
	};

	/**
	 * 获取最新书
	 */
	public void getNewBookList() {
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair(HttpRequestHelper.USERID, String.valueOf(SharedPreferencesUtils.getParam(getActivity(),HttpRequestHelper.USERID, 0))));
		params.add(new BasicNameValuePair(HttpRequestHelper.PAGE_INDEX, String.valueOf(0)));
		params.add(new BasicNameValuePair(HttpRequestHelper.PAGE_SIZE, String.valueOf(10)));
		HttpRequestHelper.getGuessYouLike(getActivity(),HttpRequestHelper.NEWEST_BOOK, params, handle,NEW_GETDATA_SUCCESS, GETDATA_FAIL);
	}

	/**
	 * 获取月榜
	 */
	public void getTopMonthBookList() {
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair(HttpRequestHelper.USERID, String.valueOf(SharedPreferencesUtils.getParam(getActivity(),HttpRequestHelper.USERID, 0))));
		params.add(new BasicNameValuePair(HttpRequestHelper.PAGE_INDEX, String.valueOf(0)));
		params.add(new BasicNameValuePair(HttpRequestHelper.PAGE_SIZE, String.valueOf(10)));
		HttpRequestHelper.getGuessYouLike(getActivity(),HttpRequestHelper.MONTH_RANK, params, handle,TOP_MONTH_GETDATA_SUCCESS, GETDATA_FAIL);
	}

	/**
	 * 获取周榜
	 */
	public void getTopWeekBookList() {
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair(HttpRequestHelper.USERID, String.valueOf(SharedPreferencesUtils.getParam(getActivity(),HttpRequestHelper.USERID, 0))));
		params.add(new BasicNameValuePair(HttpRequestHelper.PAGE_INDEX, String.valueOf(0)));
		params.add(new BasicNameValuePair(HttpRequestHelper.PAGE_SIZE, String.valueOf(10)));
		HttpRequestHelper.getGuessYouLike(getActivity(),HttpRequestHelper.WEEK_RANK, params, handle,TOP_GETDATA_SUCCESS, GETDATA_FAIL);
	}

	public void getLoacl(final int bookId) {
		Pool.getPool().execute(new Runnable() {

			@Override
			public void run() {
				BookBean bean = Cache.getPlayCacheContinueBook(bookId);
				if (bean != null) {
					handle.obtainMessage(CONTINUE_TIP, bookId, 0, bean).sendToTarget();
				}
			}
		});
	}

	public void loginSuccess() {
		/*
		 * if (listView != null) { listView.setTag("1"); } pageIndex = 0;
		 * getBookListByPageIndex();
		 */
		if (listView != null) {
			listView.clickRefresh();
		}
	}

	/**
	 * 刷新最新和热榜
	 * 
	 * @param bookId
	 */
	public void refreshNewAndTopBook(int bookId) {
		handle.obtainMessage(REFRESH_New_TopBook, bookId, 0).sendToTarget();
	}

	public ArrayList<BannerItem> getList() {
		return list;
	}

	public void setList(ArrayList<BannerItem> list) {
		this.list = list;
	}

	public void setBookList(ArrayList<BookBean> bookList) {
		this.bookList = bookList;
	}

	public ArrayList<BookBean> getNewList() {
		return newList;
	}

	public void setNewList(ArrayList<BookBean> newList) {
		this.newList = newList;
	}

	public ArrayList<BookBean> getTopList() {
		return topList;
	}

	public void setTopList(ArrayList<BookBean> topList) {
		this.topList = topList;
	}
}
